<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<script type="text/javascript">
//选择事件
function S_NodeCheck(e, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj(treeId),
        nodes = zTree.getCheckedNodes(true)
    var ids = '', names = ''
    
    for (var i = 0; i < nodes.length; i++) {
        ids   += ','+ nodes[i].id
        names += ','+ nodes[i].name
    }
    if (ids.length > 0) {
        ids = ids.substr(1), names = names.substr(1)
    }
    
    var $from = $('#'+ treeId).data('fromObj')
    
    if ($from && $from.length) $from.val(names)
}
//单击事件
function S_NodeClick(event, treeId, treeNode) {
    var zTree = $.fn.zTree.getZTreeObj(treeId)
    
    zTree.checkNode(treeNode, !treeNode.checked, true, true)
    
    event.preventDefault()
}
function getChecked()
{
	 var zTree = $.fn.zTree.getZTreeObj("j_select_tree1"),
     nodes = zTree.getCheckedNodes(true);
	 var len = nodes.length;
	 var menuCode = "";
	 for(var i = 0;i < len;i++)
	 {
		 menuCode = menuCode + nodes[i].id + ",";
	 }
	 if(menuCode != null && menuCode !=""){
		 menuCode = menuCode.substr(0,menuCode.length -1);
	 }
	 $.CurrentNavtab.find("#menuCode").val(menuCode);
	 $.CurrentNavtab.find("#authForm").submit();
}
</script>
 <form id="authForm" name="authForm" method="post" action="<%=request.getContextPath()%>/role/insertAuth.do" data-toggle="validate" data-reload-navtab="false">
 <input type="hidden" name="rolecode" value="${roleCode}"/>
 <input type="hidden" name="menucode" id="menuCode" value=""/>
<div class="bjui-pageContent">
    <div style="margin:15px auto 0; width:800px;">
        <ul id="j_select_tree1" class="ztree" data-toggle="ztree" data-expand-all="true" data-check-enable="true">
           <c:forEach items="${menu}" var="mn">
             <li data-id="${mn.ucode}" data-pid="0" <c:if test="${mn.checked}">data-checked="true"</c:if>>${mn.uname}</li>
              <c:forEach items="${mn.child}" var="cld">
                 <li data-id="${cld.ucode}" data-pid="${mn.ucode}" <c:if test="${cld.checked}">data-checked="true"</c:if>>${cld.uname}</li>
              </c:forEach>
           </c:forEach>           
        </ul>
    </div>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
        <li><button type="button" class="btn-default" data-icon="save" onclick="getChecked()">保存</button></li>
    </ul>
</div>
</form>